import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_todo_2019/page/base/base_widget.dart';
import 'package:flutter_todo_2019/page/utils/item_utils.dart';
import 'dart:io';

import 'package:flutter_todo_2019/page/utils/toast_util.dart';

class TestChildPage extends BaseWidget {
  @override
  BaseWidgetState<BaseWidget> attachState() {
    // TODO: implement attachState
    return new TestChildState();
  }
}

///子类State
class TestChildState extends BaseWidgetState<TestChildPage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print("开始");
    setAppBarVisible(false);
  }

  @override
  AppBar attachAppBar() {
    return null;
  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
//    addStr();
    showContent();
  }

//  @override
//  Widget attachContentWidget(BuildContext context) {
//    // TODO: Dart的Futures可以管理IO,不用担心线程死锁等问题
//    return FutureBuilder(
//      future: _getNews(),
//      builder: (BuildContext context, AsyncSnapshot<UserInfo> snapshot) {
//        /*表示数据成功返回*/
//        if (snapshot.hasData) {
//          UserInfo data = snapshot.data;
//          return Text("${data.name}");
//        } else {
//          return Text("Fail");
//        }
//      },
//    );
//  }
//
  @override
  Widget attachContentWidget(BuildContext context) {
    // TODO: Dart的Futures可以管理IO,不用担心线程死锁等问题
    return Container(
        child: Column(

      children: <Widget>[ItemUtils.swiperPage(context, null), Text("hello")],
    ));
  }

  ///请求接口获取数据
  Future<UserInfo> _getNews() async {
    await Future.delayed(Duration(seconds: 3), () {
      print("延时三秒后请求数据");
    });
    print("开始请求数据");
    return getTestData();
  }

  /// 执行延时任务
  UserInfo getTestData() {
    print("Call Back");
    UserInfo response = new UserInfo();
    response.name = "success";
    return response;
  }

  @override
  void onClickErrorWidget() {
    // TODO: implement onClickErrorWidget
    T.show(msg: "Erro");
  }

  int addValueStr(int one, int two) {
    return one + two;
  }
}

class UserInfo {
  String name;
}
